package com.cema.manage.zfb;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.diagnosis.DiagnosisUtils;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;

import com.alipay.api.FileItem;
import java.util.Base64;
import java.util.ArrayList;
import java.util.List;

public class AlipayFundTransUniTransfer {


    //单笔支付
    public static void main(String[] args) throws AlipayApiException {
//        // 初始化SDK
//        AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
//
//        // 构造请求参数以调用接口
//        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
//        AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
//
//        // 设置商家侧唯一订单号
//        model.setOutBizNo(RandomUtil.randomNumbers(18));
//
//        // 设置订单总金额
//        model.setTransAmount("0.1");
//
//        // 设置描述特定的业务场景
//        model.setBizScene("DIRECT_TRANSFER");
//
//        // 设置业务产品码
//        model.setProductCode("TRANS_ACCOUNT_NO_PWD");
//
//        // 设置转账业务的标题
//        model.setOrderTitle("用户提现");
//
//        // 设置收款方信息
//        Participant payeeInfo = new Participant();
//        //payeeInfo.setCertType("ALIPAY_LOGON_ID");
//        //payeeInfo.setCertNo("1201152******72917");
//        payeeInfo.setIdentity("13278873222");
//        payeeInfo.setName("何星星");
//        payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
//        model.setPayeeInfo(payeeInfo);
//        // 设置业务备注
//        model.setRemark("提现");
//
//        // 设置转账业务请求的扩展参数
//        model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");
//
//        request.setBizModel(model);
//        AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
//        System.out.println(response.getBody());
//
//        if (response.isSuccess()) {
//            System.out.println("调用成功");
//        } else {
//            System.out.println("调用失败");
//            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
//             String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
//             System.out.println(diagnosisUrl);
//        }
    }

    private static AlipayConfig getAlipayConfig() {
        String privateKey  = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvyFfnOkgQ+amuB5546AHptSDTVujX88f8/11gEcf3SODjLIWl0aEyu2SqSbiuw1aoQxYFONmuQugho4hN8QHD4I2DuC+NV99e9EnBSYOhFdy2ihlx3lu+jZn+PTDuEcWF6hwKGaBi8fhoSu+p2GjT9ech4gYLmg5ikxgrSbnl4yLCFs+iXKNx9unF3aJxqNz83pRAeYxAKKQVi4Tb6gEa806Y8Yzq/fbEVFR8PwEnBfWR7cSnE0R42Mn9yglWUytPFeMOO0o/ljmuDSEmaO61iVKnDYkyRyohqF5Kt3fCX1Lu+UoY9GiTHcFIcn5RoIYKmjVw9V7t2aBQtHEDN/5BAgMBAAECggEBAK3dZUSqGtnfd3tQwego4qt8oiknT0s6LtcI5hy9uaHXjchlIxPuEpkRTPI51NfXEgF/yWoE3xpDx0Juc8VT2kEZ/B8KsM4G2kMbMVBjHDTaYOKUGbLNEsWZXXVgpOL05QAdnPpIeqEjYGYXqJHAIX91O9YBr6UODahmgYNfeuXrZzkkFPZgD4rxrXY9Kbs9AvL3PWU/PTLGNBLNaov6THxErpBF6lNmP+jnmKMvM8X1p7ur3j3zqFhDrzqlPxPVW/C5Fusywn2hJ2odQRm6fhd1nJuDFVkIgWjLTjIDgBTfdzyevpCi/LUcuNafcjmYOEVjlctonCWtDVvKhwIpQoECgYEA/NGHNlC7bpF7U+QCijae2RRTFCbUiJw9PxbTJH1TikMbM2iRwm0zHq8ZlBMBPA4Yp30xLt+LowRLl3PHiHLZIJKiR8zx9qNV6elLVtBmITaQICmbY/nNbdzSznsUEpICr+Ru0cWl7Bz077gabS66KXNsTjpfQ9tjdjXjfmCCyskCgYEAsf6jjuIRBtUOfzi8ybu0ICtjvtwzATckm7hYm+tIBZlu3tkf9+MWyph1QAZiNcYGqRtJQDD/5JPWbUmIMgp8Z4085QS6wETrFwlCLTLC5W/LKAMZOFew8c7bzjxtHbSd9R1c/Ef1SFKkVBcLeKiWyMdQS/SRkuBRG7fZCGKuW7kCgYEAm7HNuz1ssGMXuEoq5kNNABLsNvTS3m6ZqUi9LzOfRv6cucQkP8BQQw1Ci1ZI5FsqA7utllhE/lee1d6PexB/dvfWyLEGMgXU2wC5TPV6b+nSSHxXHfKw+H+Ns2tIqUcSMJBVTwqRbB9JGHggjizAqNZUVLjOAlQRpLL7LtDwu0ECgYAWx1KhH3c0W6G+UEGAw5+6mjLqov14A1mRABd+5K5T4R3aMQkxTQOGq9oddnOtFAmYLKDEMUEePHkthUKDvOnMyrtnR6Kqpmc7jHjGlf9xI0xpc3QPzNEdMO7aRstkCNBKJRbYRlEyjzjudgCG0XRyf2dcQRE8La7TkESbGR3dKQKBgETya1A6V6n3IFwEEbohsanzzsVEVJfiIkGj3Jz15J2qbPx8AAZPBALHiiz42LB0rOw/CJfBTrbg82xbFv6PEtuu1Whd+9bJa14+TK1cSuiepY49ph0H/0prb0SFxbtNy/ma06SNvRk8vLRBoaW9qy/gTKKNveFNVmsYKtocndPa";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("2021004163616116");
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        alipayConfig.setFormat("json");
        alipayConfig.setAppCertPath("D:\\Java\\zfb\\appCertPublicKey_202100416361611.crt");
        alipayConfig.setAlipayPublicCertPath("D:\\Java\\zfb\\alipayCertPublicKey_RSA.crt");
        alipayConfig.setRootCertPath("D:\\Java\\zfb\\alipayRootCert.crt");
        return alipayConfig;
    }
}
